<template>
  <div id="loginAll">
    <div id="logo">济南黑马程序员</div>
    <div id="login1">
      <el-card class="box-card">
        <div id="form">
          <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0">
            <el-form-item prop="username">
              <el-input v-model="loginForm.username" placeholder="请输入内容"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="login">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
      },
      loginRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
      }
    }
  },
  methods: {
    login() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.$axios.post('/login', this.loginForm).then(res => {
            console.log(res)
            if (res.status === 200 && res.data.code === 0) {
              this.$message({
                message: '登录成功',
                type: 'success',
                duration: 2000
              })
              this.$router.push('/index')
            } else {
              this.$message({
                message: res.data.msg,
                type: 'error',
                duration: 2000
              })
            }
          }).catch(err => {
            console.log(err)
            this.$message({
              message: '服务器出错，请稍后再试',
              type: 'error',
              duration: 2000
            })
          })
        }
      })
    }
  }
}
</script>
<style scoped>
#loginAll {
  background-color: rgb(0, 225, 255);
  position: fixed;
  height: 100%;
  width: 100%;
  top: 0;
  left: 0;
  background-image: linear-gradient(90deg, cyan, purple);
  background-size: 600%;
  animation: myan 10s infinite;
}
@keyframes myan {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}
#logo {
  color: aliceblue;
  font-size: 25px;
  font-weight: 800;
  text-transform: uppercase;
  position: absolute;
  top: 15%;
  left: 20%;
}
#login1 {
  position: absolute;
  top: 30%;
  left: 38%;
}
.el-card {
  width: 373px;
  height: 210px;
  background-color: rgba(255, 225, 255, 0.4);
  border-radius: 15px;
}
#form {
  line-height: 60px;
  padding-left: 15px;
  padding-right: 15px;
}
</style>